package org.NooLab.itexx.app.gui.handlers;

import javax.swing.JTextArea;

import org.NooLab.utilities.logging.PrintLog;

public class DoubleClicked {
	
	boolean isRunning = false;
	Object component;
	
	long startTime=0L, secondTime=-1L;
	
	
	Thread dcThrd;
	
	// ------------------------------------------------------------------------
	public DoubleClicked(Object component){
		
		this.component = component;
		startTime = System.currentTimeMillis() ;
		(new Detector()).start();
	}
	// ------------------------------------------------------------------------
	
	
	class Detector implements Runnable{

		public Detector(){
			dcThrd = new Thread (this,"dcThrd");	
		}
		

		public void start() {
			
			// dcThrd.start() ;
		}


		@Override
		public void run() {
			isRunning = true;
			
			while (isRunning){
				PrintLog.Delay(2);
			}
			
		}
		
		
	}
	
	

	public boolean isDoubleClicked(){
		long now = System.currentTimeMillis() ;
		boolean isDouble = false;
		
		if (now-startTime>800){
			startTime = now;
			secondTime = -1L;
			return false;
		}
		
		if (now-startTime<=800){

			startTime = 0L;
			secondTime = -1L;

			isDouble = true;
		}
		
		
		return isDouble;
	}



	public void close() {
		
		isRunning = false;
		while (isRunning){
			PrintLog.Delay(1);
		}
		
	}
}
